<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script src="./lib/vue.js"></script>
</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./lib/vue.js"></script>
</head>

<body>
  <div id="app">
    <input v-model="title" type="text" />
    <hr>
    <button @click="destroyFn">销毁</button>
  </div>

  <script>

    let vm = new Vue({
      el: '#app',
      data: {
        title: 'hello',
        timer: null
      },
      methods: {
        destroyFn() {
          this.$destroy()
        }
      },
      // 生命周期
      beforeCreate() {
        // 可以用this，但是不可以使用vue对象中data和methods
        console.log('beforeCreate', this.title)
      },
      created() {
        console.log('created', this.title)
      },
      beforeMount() {

      },
      mounted() {
        this.timer && clearInterval(this.timer)
        this.timer = setInterval(() => {
          console.log(1)
        }, 1000);
      },
      beforeUpdate() {

      },
      updated() {
        console.log('updated')
      },
      beforeDestroy() {
        this.timer && clearInterval(this.timer)
      },
      destroyed() {
        console.log('destroyed')
      }
    })
  </script>
</body>

</html>